using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using DG.Tweening;
using UnityEngine.Rendering;
using UnityEngine.UI;

public class UIManager : MonoBehaviour
{
    public TextMeshProUGUI height;
    public TextMeshProUGUI hour;
    public TextMeshProUGUI min;
    public TextMeshProUGUI air;

    public TextMeshProUGUI wholeTime;
    private bool endHour;

    public Image pausePanel;
    public TextMeshProUGUI showText;

    private void OnEnable()
    {
        EventHandler.EndDive += OnEndDive;
        EventHandler.ReducedPressure += OnReducePressure;
    }

    private void OnDisable()
    {
        EventHandler.EndDive -= OnEndDive;
        EventHandler.ReducedPressure -= OnReducePressure;
    }

    private void Update()
    {
        height.text = AirConsumeManager.Instance.heightGap.ToString();
        min.text = TimeManager.Instance.diveMinute.ToString();
        air.text = AirConsumeManager.Instance.airAmount.ToString("0.0");
        wholeTime.text = "已经开始救援" + (TimeManager.Instance.gameHour == 0 ? 1 : TimeManager.Instance.gameHour).ToString() + "小时";

        hour.text = TimeManager.Instance.diveHour.ToString();

        if (Input.GetKeyDown(KeyCode.Tab)) StartCoroutine(ShowWholeHour());
    }

    private IEnumerator ShowWholeHour()
    {
        wholeTime.DOColor(new Color(1, 1, 1, 1), 1);
        yield return new WaitForSeconds(3);
        wholeTime.DOColor(new Color(1, 1, 1, 0), 1);
    }

    public void OnEndDive()
    {
        Debug.Log("1");
        StartCoroutine(Fade());
    }
    
    private void OnReducePressure(string obj)
    {
        showText.text = obj;
    }

    private IEnumerator Fade()
    {
        pausePanel.DOColor(new Color(0, 0, 0, 1), 1);
        showText.color = new Color(1, 1, 1, 1);
        yield return new WaitForSeconds(3);
        showText.color = new Color(1, 1, 1, 0);
        pausePanel.DOColor(new Color(0, 0, 0, 0), 1);
        EventHandler.CallStartDive();
    }
}
